package com.atguigu.springcloud.controller;

import cn.hutool.core.util.IdUtil;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 2 * @Author: madonghui
 * 3 * @Date: 2020/10/30 17:31
 * 4
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {
    @Value("$(server.port)")
    private String serverPort;
    @Resource
    private PaymentService paymentService;

    /**
     * 需要将服务从正确--错误--熔断降级-恢复
     * @param id
     * @return
     */
    @GetMapping("/paymentInfoOk/{id}")
    public String paymentInfo_ok(@PathVariable("id") Integer id){
       return paymentService.paymentInfo_ok(id);
    }
    @GetMapping("/paymentInfoError/{id}")
    public String paymentInfo_error(@PathVariable("id") Integer id) throws InterruptedException {

        return paymentService.paymentInfo_error(id);
    }

    //调用服务熔断
    @GetMapping("/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id")Integer id){
        return paymentService.paymentCircuitBreaker(id);
    }
}
